package cn.ds.assets.module.assets.dal.mysql.projectMember;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.projectMember.BaseProjectMemberDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.projectMember.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 项目成员 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseProjectMemberMapper extends BaseMapperX<BaseProjectMemberDO> {

    default PageResult<BaseProjectMemberDO> selectPage(BaseProjectMemberPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseProjectMemberDO>()
                .eqIfPresent(BaseProjectMemberDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(BaseProjectMemberDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(BaseProjectMemberDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseProjectMemberDO::getUserType, reqVO.getUserType())
                .inIfPresent(BaseProjectMemberDO::getId,reqVO.getIds())
                .orderByDesc(BaseProjectMemberDO::getId));
    }

    default List<BaseProjectMemberDO> selectList(BaseProjectMemberExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseProjectMemberDO>()
                .eqIfPresent(BaseProjectMemberDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(BaseProjectMemberDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(BaseProjectMemberDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseProjectMemberDO::getUserType, reqVO.getUserType())
                .inIfPresent(BaseProjectMemberDO::getId,reqVO.getIds())
                .orderByDesc(BaseProjectMemberDO::getId));
    }

    @Update("UPDATE assets_project_member SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
